<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>问答页面</title>
    <style>
        /* 在这里添加CSS样式 */
        body {
            font-family: Arial, sans-serif;
        }
        #chat-container {
            width: 80%;
            margin: 0 auto;
            margin-top: 50px;
        }
        #chat-input {
            width: 100%;
            padding: 10px;
            font-size: 16px;
        }
        #chat-output {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ccc;
            height: 300px;
            overflow-y: scroll;
        }
    </style>
</head>
<body>
    <div id="chat-container">
        <h2>与星火认知大模型对话</h2>
        <textarea id="chat-output" readonly></textarea>
        <input type="text" id="chat-input" placeholder="输入你的问题...">
        <button id="send-button">发送</button>
    </div>
    <script>
        // 在这里添加JavaScript代码
        document.getElementById('send-button').addEventListener('click', function() {
            var input = document.getElementById('chat-input').value;
            var output = document.getElementById('chat-output');
            fetch('/chat', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ input: input })
            }).then(response => response.json())
            .then(data => {
                output.value += '大模型: ' + data.response + '\n';
                output.scrollTop = output.scrollHeight; // 滚动到最底部显示最新消息
            }).catch(error => {
                console.error('Error:', error);
            });
            document.getElementById('chat-input').value = ''; // 清空输入框以便输入下一个问题
        });
    </script>
</body>
</html>